home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.lang.perl
- Path: news.eng.convex.com!arco!usenet
- From: "James W. Bielak" <bielak@arco.com>
- Subject: Re: Random File Access - I don't get it
- X-Nntp-Posting-Host: 130.201.20.122
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <Dp8nq5.4Eo@news.arco.com>
- Sender: usenet@news.arco.com
- Content-Transfer-Encoding: 7bit
- Organization: ARCO
- References: <3160DE1E.495C@teleport.com>
- Mime-Version: 1.0
- Date: Tue, 2 Apr 1996 14:18:05 GMT
- X-Mailer: Mozilla 1.1 (X11; U; SunOS 4.1.3_U1 sun4c)
- X-Url: news:3160DE1E.495C@teleport.com
-
- Scott Kinard <kinards@teleport.com> wrote:
- >Greetings,
- >
- > As I was coding a simple program to randomly read lines from a text file it occurred
- >to me something was amiss. This is probably some fundamental oversight on my part, but
- >some illumination would be helpful...
- >
- > Suppose I have two files, one contains text (1 line of random length text per
- >'record') and another which is my index into the text file, which contains the starting
- >and ending byte positions in the text file for each 'record'. Now the question..
- >
- >Suppose the text file has 2,000,000 entries. Now, what's the difference in reading
- >1,000,000 lines from the index file to find the starting and ending byte positions in
- >the text file for record 1,000,000, and then seeking these in the text file, rather than
- >just reading 1,000,000 times from the text file to get the same 'record' in the first
- >place?
- >
- >-Scott
-
- Which of these do you think will take longer:
-
- open index file
- seek offset (1,000,000 * record size)
- open text file
- seek record offset
-
- or...
-
- for (i=0;i<1000000;1++)
- read a buffer
-
- jwb
-
-